import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
// import { OptionalAuthGuard } from '@wwjCommon/security/guards/optional-auth.guard';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { MemberSignService } from '../../services/api/member-sign.service';

/**
 * MemberSignController
 * 对应 PHP: MemberSign Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('member')
@Controller('api/member')
@UseGuards(ApiCheckTokenGuard)
export class MemberSignController {
  constructor(private readonly memberSignService: MemberSignService) {}

  /**
   * lists
   * 路由: GET sign
   * PHP路由: Route::get('sign', 'member.MemberSign/lists')
   */
  @Get('sign')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'lists' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.memberSignService.getPage();
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * info
   * 路由: GET sign/:sign_id
   * PHP路由: Route::get('sign/:sign_id', 'member.MemberSign/info')
   */
  @Get('sign/:sign_id')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'info' })
  async info(@Param('sign_id') sign_id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: info

      return await this.memberSignService.getInfo(sign_id);
    } catch (error) {
      throw new BusinessException('info操作失败', error);
    }
  }

  /**
   * sign
   * 路由: POST sign
   * PHP路由: Route::post('sign', 'member.MemberSign/sign')
   */
  @Post('sign')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'sign' })
  async sign(@Body() data: SignDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: sign

      return await this.memberSignService.sign();
    } catch (error) {
      throw new BusinessException('sign操作失败', error);
    }
  }

  /**
   * signInfo
   * 路由: GET sign/info/:year/:month
   * PHP路由: Route::get('sign/info/:year/:month', 'member.MemberSign/signInfo')
   */
  @Get('sign/info/:year/:month')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'signInfo' })
  async signInfo(
    @Param('year') year: string,
    @Param('month') month: string,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: signInfo

      return await this.memberSignService.getSignInfo(year, month);
    } catch (error) {
      throw new BusinessException('signInfo操作失败', error);
    }
  }

  /**
   * getDayAward
   * 路由: GET sign/award/:year/:month/:day
   * PHP路由: Route::get('sign/award/:year/:month/:day', 'member.MemberSign/getDayAward')
   */
  @Get('sign/award/:year/:month/:day')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'getDayAward' })
  async getDayAward(
    @Param('year') year: string,
    @Param('month') month: string,
    @Param('day') day: string,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getDayAward

      return await this.memberSignService.getDayAward(year, month, day);
    } catch (error) {
      throw new BusinessException('getDayAward操作失败', error);
    }
  }

  /**
   * signConfig
   * 路由: GET sign/config
   * PHP路由: Route::get('sign/config', 'member.MemberSign/signConfig')
   */
  @Get('sign/config')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'signConfig' })
  async signConfig(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: signConfig

      return await this.memberSignService.getSignConfig();
    } catch (error) {
      throw new BusinessException('signConfig操作失败', error);
    }
  }
}
